package com.fyt.ZhongYaoApp.service.impl;

import com.fyt.ZhongYaoApp.mapper.HospitalMapper;
import com.fyt.ZhongYaoApp.pojo.Hospital;
import com.fyt.ZhongYaoApp.pojo.PageBean;
import com.fyt.ZhongYaoApp.pojo.pg.HospitalPG;
import com.fyt.ZhongYaoApp.pojo.vo.DoctorQueery;
import com.fyt.ZhongYaoApp.pojo.vo.HospitalVO;
import com.fyt.ZhongYaoApp.service.HospitalService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    HospitalMapper hospitalMapper;


    @Override
    public List<Hospital> hospitalList() {

        return hospitalMapper.hospitalList();
    }

    @Override
    public void add(Hospital hospital) {
        hospitalMapper.add(hospital);
    }

    @Override
    public String getNameById(Hospital hospital) {
        return hospitalMapper.getNameById(hospital);
    }

    @Override
    public PageBean<HospitalVO> querryHospital(HospitalPG hospitalPG) {

        // 创建PageBean对象
        PageBean<HospitalVO> pageBean = new PageBean();

        // 开启分页查询pageHelper
        PageHelper.startPage(hospitalPG.getPageNum(),hospitalPG.getPageSize());

        // 调用Mapper
        List<HospitalVO> list = hospitalMapper.querryHopital(hospitalPG);

        Page<HospitalVO> page = (Page<HospitalVO>) (list);

        // 把数据填充到PageBean对象中
        pageBean.setTotal(page.getTotal());
        pageBean.setItems(page.getResult());

        return pageBean;

    }

    @Override
    public Hospital querryHospitalById(Hospital hospital) {
        return hospitalMapper.querryHopitalById(hospital);
    }


}
